package com.expmanage.actions.manager;

import com.expmanage.models.StudentMapper;
import com.opensymphony.xwork2.*;

import java.util.*;

import org.apache.ibatis.session.*;

import static com.expmanage.actions.utils.DatabaseConfigure.*;

@SuppressWarnings("serial")
public class checkStudents extends ActionSupport{
	List<Integer> sid_check_list = null;
	List<Integer> sid_uncheck_list = null;
	List<Integer> sid_del_list = null;

	public List<Integer> getSid_check_list() {
		return sid_check_list;
	}

	public void setSid_check_list(List<Integer> sid_check_list) {
		this.sid_check_list = sid_check_list;
	}

	public List<Integer> getSid_uncheck_list() {
		return sid_uncheck_list;
	}

	public void setSid_uncheck_list(List<Integer> sid_uncheck_list) {
		this.sid_uncheck_list = sid_uncheck_list;
	}

	public List<Integer> getSid_del_list() {
		return sid_del_list;
	}

	public void setSid_del_list(List<Integer> sid_del_list) {
		this.sid_del_list = sid_del_list;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		if(sid_check_list==null && 
			sid_uncheck_list==null &&
			sid_del_list==null) return "success";
		
		SqlSession session = sqlSessionFactory.openSession();		
		try {
			StudentMapper mapper = session.getMapper(StudentMapper.class);
			if(sid_check_list!=null)
				for(Integer id : sid_check_list){
					mapper.checkStudent(id);
				}
			if(sid_uncheck_list!=null)
				for(Integer id : sid_uncheck_list){
					mapper.uncheckStudent(id);
				}
			if(sid_del_list!=null)
				for(Integer id : sid_del_list){
					mapper.deleteStudent(id);
				}
			session.commit();
		} catch(Throwable e){
			e.printStackTrace();
			return "error";
		}finally {
			session.close();
		}
		return "success";
	}

	
}
